﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace eShop.DataAccess.Converter
{
    public class CityConverter
    {
        public static void AttachAssociation(List<Model.MetaData.City> models, List<Model.MetaData.State> associations)
        {
            foreach (Model.MetaData.City model in models)
            {
                model.CityState = associations.Single(c => c.Id == model.CityState.Id);
                model.CityState.Cities.Add(model);
            }
        }

        public static List<Model.MetaData.City> ConvertToModelObject(List<Entity.City> entities)
        {
            List<Model.MetaData.City> models = new List<Model.MetaData.City>(entities.Count);
            foreach (Entity.City entity in entities)
            {
                models.Add(ConvertToModelObject(entity));
            }
            return models;
        }

        public static Model.MetaData.City ConvertToModelObject(Entity.City entity)
        {
            if (entity == null) return null;
            Model.MetaData.City model = new Model.MetaData.City();
            model.Id = entity.Id;
            model.Name = entity.Name;
            model.CityState = new Model.MetaData.State() { Id = entity.StateId };
            return model;
        }
    }
}
